package com.sinosoft.workflow.biz.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.sinosoft.workflow.biz.dao.FlowWorkDao;
import com.sinosoft.workflow.biz.entity.FlowWork;

/**
 * 
 * 【工作流配置Dao接口，工作流与业务进行关联】
 * @author chihouliang
 * @date 2016年8月18日 下午6:06:40 
 * @version V1.0
 */
@Repository
public class FlowWorkDaoImpl extends HibernateDaoSupport  implements FlowWorkDao{

    @Override
    public void save(FlowWork cFlowWork) throws Exception {
        this.getHibernateTemplate().save(cFlowWork);
    }

    /**通过sql语句查询流程实例id*/
    @SuppressWarnings("unchecked")
    @Override
    public String query(String cBizNo, Integer cFlowCode) throws Exception {
        List<FlowWork> list= this.getHibernateTemplate().find("from FlowWork f where f.bizNo=? and f.flowCode=?", cBizNo, cFlowCode);
        //流程实例Id
        String tProcessInstanceId = "";
                
        if(list!=null && list.size()>0){
            FlowWork tFlowWork = list.get(0);
            
            if(tFlowWork!=null){
                tProcessInstanceId = tFlowWork.getProcessInstanceId();
            }
        }
        
        return tProcessInstanceId;
    }

    @Resource(name="sessionFactory")
    public final void setSessionFactoryDi(SessionFactory sessionFactory) {
        this.setSessionFactory(sessionFactory);
    }
}
